import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../components/Home.vue'
import Login from '../components/Login.vue'
import Welcome from '../components/Welcome.vue'
import Goods from '../Pages/Goods/index.vue';
import AddGoods from "../Pages/Goods/addGoods.vue"
import EditGoods from '../Pages/Goods/editGoods.vue';

import Order from "../Pages/Order"


import Topic from '@/components/topic/';
import MerchantList from '../components/merchant/'

//商户管理
import AppVersionList from '../components/merchant/AppVersionList.vue'
import { Input, Button, Form, FormItem, Container, Header, Aside, Main, Breadcrumb, BreadcrumbItem, Row, Col, Table, TableColumn } from 'element-ui'

Vue.use(VueRouter)
Vue.use(Button)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(Input)
Vue.use(Container)
Vue.use(Header)
Vue.use(Aside)
Vue.use(Main)
Vue.use(Breadcrumb)
Vue.use(BreadcrumbItem)
Vue.use(Row)
Vue.use(Col)
Vue.use(Table)
Vue.use(TableColumn)

const routes = [
  { path: '/', redirect: 'login', },
  { path: '/home', name: 'Home', component: Home, redirect: '/welcome',
    children: [
        { path: '/welcome', component: Welcome },
        { path: '/merchant', component: MerchantList },
        { path: '/appVersionList', component: AppVersionList },
        { path: '/topic', component: Topic },
        { path:'/goods', component:Goods},
        {path:'/goods/add', component:AddGoods },
        {path:'/goods/edit', component:EditGoods },

        {path:'/order', component:Order },
    ]
  },
  { path: '/merchantList', name: 'MerchantList', component: MerchantList },
  { path: '/login', name: 'Login', component: Login },
]
const router = new VueRouter({
  routes
})

//路由判断 to 将要访问的路径  from代表从哪个路径跳转而来   next 是一个函数，表示放行 next()放行 ntxt('/login') 表示强制跳转
router.beforeEach((to, from, next) => {
  //登录页直接放行  
  if (to.path == '/login') return next()
  //获取token
  // const tokenStr = window.sessionStorage.getItem("token")
  // if (!tokenStr) return next('/login');
  next();
});

export default router




